package com.fancy.learncenter.ui.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;

/**
 * 防止滚动条图片被拉伸
 * Created by shiweiwei on 2018/1/5.
 */

public class CustomRecycleView extends RecyclerView{
    public CustomRecycleView(Context context) {
        super(context);
    }

    public CustomRecycleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public int computeVerticalScrollExtent() {
        return 1;
    }

    @Override
    public int computeVerticalScrollOffset() {

        int sRange = super.computeVerticalScrollRange();
        int sExtent = super.computeVerticalScrollExtent();
        int range = sRange - sExtent;
        if(range == 0){
            return 0;
        }
        return (int) (sRange * super.computeVerticalScrollOffset() * 1.0f / range);
    }
}
